package com.mkj.container;

import javax.swing.*;

/**
 * @Author Arrebol
 * @Date 2024/8/6 20:26
 * @Project graphical programming
 * @Description：
 * 页面板组件基本演示
 */
public class JTabbedPaneTest {

    private final JFrame frame = new JFrame("展示页面板组件");
    private JTabbedPane tabbedPane = new JTabbedPane(SwingConstants.LEFT,JTabbedPane.SCROLL_TAB_LAYOUT);

    public void init(){
        //组装视图
        //添加标签
        tabbedPane.addTab("用户管理",new ImageIcon("swing\\image\\container\\open.gif"),
                new JList<>(new String[]{"用户1","用户2","用户3"}));
        tabbedPane.addTab("商品管理",new JList<>(new String[]{"商品1","商品2","商品3"}));
        tabbedPane.addTab("订单管理",new ImageIcon("swing\\image\\container\\open.gif"),
                new JList<>(new String[]{"订单1","订单2","订单3","订单4"}));
        //完成设置
        tabbedPane.setEnabledAt(0,false);
        tabbedPane.setSelectedIndex(1);
        //监听标签面板的选中情况
        tabbedPane.addChangeListener(e -> {
            int index = tabbedPane.getSelectedIndex();
            JOptionPane.showMessageDialog(frame,"当前选中了第"+(index+1)+"个标签");
        });
        frame.add(tabbedPane);
        //设置窗口大小
        frame.setBounds(400,400,400,400);
        //固定窗口大小
        frame.setResizable(false);
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
    public static void main(String[] args) {
        new JTabbedPaneTest().init();
    }
}
